{extend name="base"}
{block name="main"}
<div class="details">
    <div class="details_operation clearfix">
        <div class="bui_select">
            <input type="button" value="添&nbsp;&nbsp;加" class="add" onclick="add()">
        </div>
        <div class="fr">
            <div class="text">
                <span>商品价格：</span>
                <div class="bui_select">
                    <select id="" class="select" onchange="change(this.value)">
                    	<option>-请选择-</option>
                        <option value="iPrice asc" >由低到高</option>
                        <option value="iPrice desc">由高到底</option>
                    </select>
                </div>
            </div>
            <div class="text">
                <span>上架时间：</span>
                <div class="bui_select">
                 <select id="" class="select" onchange="change(this.value)">
                 	<option>-请选择-</option>
                        <option value="pubTime desc" >最新发布</option>
                        <option value="pubTime asc">历史发布</option>
                    </select>
                </div>
            </div>
            <div class="text">
                <span>搜索</span>
                <input type="text" value="" class="search"  id="search" onkeypress="search()" >
            </div>
        </div>
    </div>
    <!--表格-->
    <table class="table" cellspacing="0" cellpadding="0">
        <thead>
            <tr>
                <th width="10%">编号</th>
                <th width="20%">商品名称</th>
                <th width="10%">商品分类</th>
                <th width="10%">是否上架</th>
                <th width="15%">上架时间</th>
                <th width="10%">慕课价格</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
	        {volist name="list" id="vo"}
	            <tr>
	                <!--这里的id和for里面的c1 需要循环出来-->
	                <td><input type="checkbox" id="c1" class="check" value={$vo.id}><label for="c1" class="label">{$vo.id}</label></td>
	                <td>{$vo.gName}</td>
	                <td>{$vo.cName}</td>
	                <td>
	                	{$vo['isShow']==1?"上架":"下架"}
	                </td>
	                <td>{$vo.pubTime|date="Y-m-d H:i:s", ###}</td>
	                <td>{$vo.iPrice}元</td>
	                <td align="center">
	    				<input type="button" value="详情" class="btn" onclick="showDetail({$vo.id},'{$vo.gName}')">
    					<input type="button" value="修改" class="btn" onclick="edit()">
    					<input type="button" value="删除" class="btn" onclick="del({$vo.id})">
	                	<div id="showDetail{$vo.id}" style="display:none;">
	            			<table class="table" cellspacing="0" cellpadding="0">
		                		<tr>
		                			<td width="20%" align="right">商品名称</td>
		                			<td>{$vo.gName}</td>
		                		</tr>
		                		<tr>
		                			<td width="20%"  align="right">商品类别</td>
		                			<td>{$vo.cName}></td>
		                		</tr>
		                		<tr>
		                			<td width="20%"  align="right">商品货号</td>
		                			<td>{$vo.gSN}</td>
		                		</tr>
		                		<tr>
		                			<td width="20%"  align="right">商品数量</td>
		                			<td>{$vo.gNum}</td>
		                		</tr>
		                		<tr>
		                			<td  width="20%"  align="right">商品价格</td>
		                			<td>{$vo.mPrice}</td>
		                		</tr>
		                		<tr>
		                			<td  width="20%"  align="right">促销</td>
		                			<td>{$vo.iPrice}</td>
		                		</tr>
		                		<tr>
		                			<td width="20%"  align="right">商品图片</td>
		                			<td>
			                			{volist name="vo.imgPath" id="img" }
			                				<img width="100" height="100" src="/uploads/picture/goods/{$img.albumPath}" alt=""/> &nbsp;&nbsp;
			                			{/volist}
		                			</td>
		                		</tr>

		                		<tr>
		                			<td width="20%"  align="right">是否上架</td>
		                			<td>
		                				{$vo['isShow']==1?"上架":"下架"}
		                			</td>
		                		</tr>
		                		<tr>
		                			<td width="20%"  align="right">是否热卖</td>
		                			<td>
		                				{$vo['isHot']==1?"热卖":"正常"}
		                			</td>
		                		</tr>
		                	</table>
	            			<span style="display:block;width:80%; ">
			                	商品描述<br/>
			                	{$vo.gDesc}
		                	</span>
	            		</div>
	                </td>
	            </tr>
            {/volist}
			{gt name="totalPage" value="1"}
                <tr>
                    <td colspan="7">{$page|showpage="$totalPage","keywords=". $Think.get.keywords . "&order=" . $Think.get.order}</td>
                </tr>
            {/gt}
        </tbody>
    </table>
</div>
<script type="text/javascript">
	function showDetail(id,t){
		$("#showDetail"+id).dialog({
			  height:"auto",
		      width: "auto",
		      position: {my: "center", at: "center",  collision:"fit"},
		      modal:false,//是否模式对话框
		      draggable:true,//是否允许拖拽
		      resizable:true,//是否允许拖动
		      title:t,//对话框标题
		      show:"slide",
		      hide:"explode"
		});
	}
    function add(){
        window.location="{:url('admin/goods/add')}";  
    }
    function edit(){
        window.location="{:url('admin/goods/edit')}?id={$vo.id}";
    }
    function del(id){
        if(window.confirm("您确定要删除吗？删除之后不可以恢复哦！！！")){
            $.ajax({
                cache: true,
                type: "GET",
                url : '{:url('admin/goods/delete')}?id='+id,
                data: {'id':id},
                async: false,
                success: function(data) {
                    if (data.code) {
                        alert(data.msg);
                        setTimeout(function () {
                            location.href = data.url;
                        }, 0);
                    } else {
                    alert(data.msg);
                    }
                },
                error: function(request) {
                    alert("页面错误");
                }
            });
        }
    }
	function search(){
		if(event.keyCode==13){
			var val=document.getElementById("search").value;
			window.location="{:url('admin/goods/index')}?order={$Think.get.order}&keywords="+val;
		}
	}
	function change(val){
		window.location="{:url('admin/goods/index')}?order="+val+"&keywords={$Think.get.keywords}";
	}
	
</script>
{load href='__PUBLIC__/static/jquery-ui-1.12.1/jquery-ui.css'}
{load href='__PUBLIC__/static/jquery-ui-1.12.1/jquery-ui.js'}
{/block}